/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-07 09:26:03
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-02-28 14:28:54
 * @FilePath: /yt-devops/lib/pages/tasks/task_list/task_list_model.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:get/get.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:yt_devops/model/info_item.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/utils/enums.dart';

class TaskListModel {
  int? id;
  int? userId;
  int? status;
  TaskType? type;
  String? userName;
  String? phone;
  String? timeOfAppointment;
  String? address;
  String? name;
  String? siteName;
  String? createTime;

  TaskListModel(
      {this.id,
      this.userId,
      this.status,
      this.userName,
      this.phone,
      this.timeOfAppointment,
      this.type,
      this.name,
      this.siteName,
      this.address,
      this.createTime});

  factory TaskListModel.fromJson(Map<String, dynamic> json) => TaskListModel(
        id: json['id'],
        userId: json['userId'],
        userName: json['userName'],
        phone: json['phone'],
        timeOfAppointment: json['timeOfAppointment'],
        address: json['address'],
        name: json['name'],
        status: json['status'],
        siteName: json['siteName'],
        type: $enumDecodeNullable(
          $TaskTypeEnumMap,
          json['type'],
        ),
        createTime: json['createTime'],
      );

  String? getStatus() {
    if (type == TaskType.install) {
      return $enumDecodeNullable($InstallTaskStatusTypeEnumMap, status)?.label;
    } else if (type == TaskType.maintenance) {
      return $enumDecodeNullable($RepairTaskStatusTypeEnumMap, status)?.label;
    } else {
      return $enumDecodeNullable($ReportTaskStatusTypeEnumMap, status)?.label;
    }
  }

  List<InfoItem> get infoLists {
    if (type == TaskType.install) {
      return [
        InfoItem('${ResKey.workOrderCode.tr}：', id?.toString() ?? ''),
        InfoItem('${ResKey.appointmentTime.tr}：', timeOfAppointment ?? ''),
        InfoItem('${ResKey.customerAddress.tr}：', address?.toString() ?? ''),
      ];
    } else if (type == TaskType.maintenance) {
      return [
        InfoItem('${ResKey.workOrderCode.tr}：', id?.toString() ?? ''),
        InfoItem('${ResKey.maintenanceTime.tr}：', timeOfAppointment ?? ''),
      ];
    } else {
      return [
        InfoItem('${ResKey.workOrderCode.tr}：', id?.toString() ?? ''),
        InfoItem('${ResKey.failureTitle.tr}：', name ?? ''),
        InfoItem('${ResKey.declarationTime.tr}：',
            createTime?.substring(0, 10) ?? ''),
      ];
    }
  }
}
